<?php
class Comments_model extends CI_Model{
	
	function add($id_user,$id_sitio,$comentario){
		$data = array(
			'id_sitio'			=>$id_sitio,
			'id_usuario'		=>$id_user,
			'comentario'		=>$comentario
		);
		
		$this->db->insert('comentarios',$data);
		return $this->db->insert_id();
	}
	
	function get($id_sitio){
		$this->db->select('comentario , fecha , users.username, users.id AS userID, comentarios.id');
		$this->db->from('comentarios');
		$this->db->join('users','users.id = comentarios.id_usuario');
		$this->db->where('id_sitio', $id_sitio);
		$this->db->order_by("fecha", "asc"); 
		return $this->db->get()->result();
	}
	
	function getUser($id_coment){
		$this->db->select('id_usuario');
		$this->db->where('id',$id_coment);
		return $this->db->get('comentarios')->result();
	}
	
	function eliminar($id_coment){
		$this->db->where('id', $id_coment);
		$this->db->delete('comentarios'); 
	}
}